home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / DSHJ2 / STARTUP.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  15.6 KB  |  571 lines

  1. /**************************************************************************/
  2. /*  FILE:  STARTUP.C        PROGRAM TITLE: DeskSET II Alpha Version   */
  3. /*  Date Created: 12/15/87                          */ 
  4. /*  Last Modified: 09/21/88                          */
  5. /*  Modified from aps.c - G.O. Graphics 1987/1988/1989?              */
  6. /*                                      */
  7. /*  Description: Entry into DeskSET                      */
  8. /*  Routines:    o main()       - Start Application Here          */
  9. /*        o gsx_mon()    - Turn on Mouse and Release Semaphor      */
  10. /*        o gsx_moff()    - Turn off Mouse and Seize Semaphor      */
  11. /*        o open_work()   - Open workstations, resource and windows */
  12. /*        o close_vwork()    - Close in emergency              */
  13. /*        o close_work()    - close at end of day...          */
  14. /*        o laser_open()  - Open Laser Workstation          */
  15. /*         o laser_close() - Close Laser Workstation          */
  16. /*        o page_open()   - Open Memory Workstation          */
  17. /*        o page_close()  - Close Memory Workstation          */
  18. /**************************************************************************/
  19.  
  20.  
  21. /**************************************************************************/
  22. /* INCLUDE FILES                              */
  23. /**************************************************************************/
  24. #include "define.h"
  25. #include "gemdefs.h"
  26. #include <osbind.h>
  27. #include "alert.h"
  28.  
  29. /**************************************************************************/
  30. /* DEFINES                                  */
  31. /**************************************************************************/
  32. #define SCANX   640                /* scan buffer resolution */
  33. #define SCANY   1088                /* x and y resolution     */
  34.                         /* Legal Size Paper      */
  35. #define PREVIEW_SIZE 352600L            /* Calced at 80dpi      */
  36.                         /* (648 * 1088 * 4)/8     */
  37. #define LASER_SIZE   1223190L            /* calced at 300dpi      */
  38.  
  39. #define SCAN_SIZE    88128L
  40.  
  41. /**************************************************************************/
  42. /* EXTERNALS                                  */
  43. /**************************************************************************/
  44. extern char rscerr[],rscerr1[],rscerr2[];    /* Error Alert Boxes...   */
  45. extern int gl_apid;
  46. extern long BADDR;
  47. extern int dummy;
  48. extern int *bltbuffer;                /* CS icon save buffer    */
  49. extern int sdevm;
  50. extern char scanerr[];
  51. extern char preverr[];
  52.  
  53. extern unsigned char *get_lmem();
  54. extern unsigned char *get_lcmem();
  55. extern char *lmalloc();
  56. extern char *lcalloc();
  57. extern char *pbuff;
  58.  
  59. extern int axdpi[];
  60. extern int aydpi[];
  61.  
  62. extern int half_xdpi[];
  63. extern int half_ydpi[];
  64.  
  65. extern unsigned int xdpi[];        /* right, from ifout.c           */
  66. extern unsigned int ydpi[];        /* and we shouldn't really be     */
  67.                     /* touching this...          */
  68.  
  69. extern unsigned int gdostst();
  70.  
  71.  
  72. extern char fbuffer[];
  73.  
  74. /**************************************************************************/
  75. /* GLOBAL VARIABLES                              */
  76. /**************************************************************************/
  77. int contrl[12];                           /* Bindings... */
  78. int intin[256];
  79. int ptsin[256];
  80. int intout[256];
  81. int ptsout[256]; 
  82.  
  83. int charw,charh;                       /* Graf_handle */
  84. int boxw,boxh;                       
  85.  
  86. int gl_wchar;                           /* System sizes*/
  87. int gl_hchar;
  88. int gl_wbox;
  89. int gl_hbox;
  90.  
  91. int phys_handle;                    /* Physical Handle        */
  92. int shandle;                    /* Screen Handle          */
  93. int phandle;                    /* Printer Handle         */
  94. int mhandle;                    /* Memory Handle          */
  95. int xor_handle;                    /* drawing handle      */
  96. int rule_handle;
  97.  
  98. int sxres;                    /* Screen x resolution    */
  99. int syres;                    /* Screen y resolution    */
  100. int splane;                    /* Screen Num of planes   */
  101.  
  102. int scan_xres,scan_yres;            /* scan buffer x,y rez    */
  103. int pxres,pyres;                /* Printer Resolutions    */
  104. int mxres,myres;                /* Memory resolutions     */
  105. int oldpal[16];                    /* Old Palette            */
  106.  
  107. unsigned long pageim;                /* Ptr to laser buffer    */
  108. unsigned long pagesc;                /* ptrs to memory driver  */
  109. unsigned long page_ptr;                /* buffer...              */
  110. unsigned long scanesc;                /* Ptr to scan buffer     */
  111. unsigned long scanptr;                /* ditto...          */
  112.  
  113. unsigned long prev_bytes;
  114. unsigned long laser_bytes;
  115. unsigned long scan_bytes;
  116.  
  117. int cur_point_size;                /* Current Point Size      */
  118.  
  119. int     mouse_on;                /* Mouse On/Off Flag      */
  120. long     lineav;                    /* Get base of linea vars */
  121. int    *gcurx;                    /* Ptr to mouse x position*/
  122. int    *gcury;                    /* Ptr to mouse y position*/
  123.  
  124. char    *gbutton;                /* Ptr to button state    */
  125. FDB page_MFDB;                    /* Preview Memory Form    */
  126. FDB laser_MFDB;                    /* Laser Memory Form      */
  127.  
  128. extern int maxpat;            /* Graphic screen device limits   */
  129. extern int maxhatch;
  130. extern int maxlwidth;
  131. extern int maxlstyles;
  132.  
  133. long pagebytes;
  134.  
  135. char envstr[80];
  136.  
  137. /**************************************************************************/
  138. /* Function: main()                              */
  139. /* Description: Must I really explain?                      */
  140. /**************************************************************************/
  141. main(argc,argv)
  142. int argc;
  143. char *argv[];
  144. {
  145.         int drv;
  146.         char ch;
  147.         char *pathptr;
  148.         int i;
  149.  
  150.     lineai();                /* Get base of linea addr */
  151.     gcurx = lineav - 602;            /* Ptr to mouse x pos.    */
  152.     gcury = lineav - 600;            /* Ptr to mouse y pos.    */
  153.         gbutton = lineav - 348;            /* Ptr to button state    */
  154.  
  155.         appl_init();
  156.         if(argv[1])
  157.         {
  158.            pathptr = fbuffer;
  159.            *pathptr++ = (drv = Dgetdrv())+'A';
  160.        *pathptr++ = ':';
  161.        Dgetpath(pathptr,drv+1);
  162.        strcat(pathptr,"\\");
  163.     }
  164.  
  165.         strcpy(envstr,"DESK2.PRG");
  166.         shel_find(envstr);
  167.         if(envstr[1] == ':' && argv[1])
  168.     {
  169.        ch = envstr[0];
  170.        ch -= 'A';
  171.        drv = (int)ch;
  172.        if(drv >= 0 && drv <= 15)
  173.         Dsetdrv(drv);
  174.        for(i=strlen(envstr); i && !instring(envstr[i],"\\:");
  175.                         envstr[i--] = '\0');
  176.        Dsetpath(&envstr[2]);
  177.     }
  178.                
  179.         if(!rsrc_load("DESKSET2.RSC"))
  180.         alert_cntre(ALERT1);
  181.         else
  182.         {
  183.       if((phys_handle = graf_handle(&gl_wchar,&gl_hchar,
  184.                       &gl_wbox,&gl_hbox))
  185.                       && open_work())
  186.             front_end(argv[1]);
  187.         }
  188.     appl_exit();
  189. }
  190.  
  191.  
  192.  
  193.  
  194. /*************************************************************************/
  195. /* Function:    gsx_mon()                         */
  196. /* Description: Turn mouse on and release screen metaphor.               */
  197. /*************************************************************************/
  198. gsx_mon()
  199. {
  200.     if(!mouse_on)
  201.     {
  202.         graf_mouse(M_ON,0x0L);
  203.         wind_update(FALSE);
  204.         mouse_on = TRUE;
  205.     }
  206. }
  207.  
  208.  
  209.  
  210. /*************************************************************************/
  211. /* Function:    gsx_moff()                         */
  212. /* Description: Turn mouse off and grab screen metaphor.                 */
  213. /*************************************************************************/
  214. gsx_moff()
  215. {
  216.     if(mouse_on)
  217.       {
  218.         graf_mouse(M_OFF,0x0L);
  219.         wind_update(TRUE);
  220.         mouse_on = FALSE;   
  221.     }
  222. }
  223.  
  224.  
  225.  
  226. /*************************************************************************/
  227. /* Function:    open_work();                         */
  228. /* Description: o Open Workstations                     */
  229. /*              o Allocate Default Buffers.                 */
  230. /*        o Load Resource                         */
  231. /*        o Display menu bar                     */
  232. /*************************************************************************/
  233. open_work()
  234. {
  235.     register unsigned int i;
  236.  
  237.     sdevm = Getrez();
  238.     if(!sdevm)
  239.     {
  240.     alert_cntre(ALERT35);
  241.     return(0);
  242.     }
  243.     intin[0] = sdevm + 2;                /* Get Rez...    */
  244.     for(i = 1; i < 10; i++) intin[i] = 1;        /* Set up array  */
  245.     intin[10] = 2;
  246.     rule_handle = xor_handle = shandle = phys_handle;    /* copy handle   */
  247.     v_opnvwk(intin,&shandle,intout);            /* open virtual  */
  248.     if(!shandle)
  249.     {    
  250.           rsrc_free();
  251.           return(0);                     /* Exit if error */
  252.     }
  253.  
  254.     sxres = intout[0] + 1;                 /* Get Resolution*/
  255.     syres = intout[1] + 1;
  256.  
  257.  
  258.  
  259.     maxpat = intout[11] + 1;        /* + 1 for hollow     */
  260.     maxhatch = intout[12];
  261.     maxlwidth = intout[51];
  262.     maxlstyles = 6;
  263.     vq_extnd(shandle,1,intout);
  264.     splane= intout[4];                    /* Get Num planes*/
  265.  
  266.     if(gdostst() == -2)
  267.     {
  268.     alert_cntre(ALERT36);
  269.     rsrc_free();
  270.     v_clsvwk(shandle);
  271.     return(0);
  272.     }
  273.  
  274.  
  275.     intin[0] = sdevm + 2;                /* Get drawing   */
  276.     for(i = 1; i < 10; i++) intin[i] = 1;        /* handle        */
  277.     intin[10] = 2;
  278.     v_opnvwk(intin,&xor_handle,intout);    
  279.     if (!xor_handle)
  280.     {
  281.        rsrc_free();
  282.        v_clsvwk(shandle);
  283.            return(0);
  284.     }
  285.  
  286.  
  287.     intin[0] = sdevm + 2;
  288.     for(i = 1; i < 10; i++) intin[i] = 1;
  289.     intin[10] = 2;
  290.     v_opnvwk(intin,&rule_handle,intout);
  291.     if(!rule_handle)
  292.     {
  293.        rsrc_free();
  294.        v_clsvwk(xor_handle);
  295.        v_clsvwk(shandle);
  296.        return(0);
  297.     }
  298.  
  299.     mhandle = 0;                      /* set handles   */
  300.     scanesc = scanptr = pagesc = page_ptr = 0L;        /* and pointers  */
  301.  
  302.     adjustdpi();
  303.     initsys();        /* CS moved from front_end */
  304.     laser_bytes = LASER_SIZE;
  305.  
  306.     mouse_on = TRUE;
  307.     gsx_moff();
  308.  
  309.      /*    numbytes = (((xdpi * 8inches) * (ydpi * 14))/8)        */
  310.     /*    preview buffer = numbytes * 4;                */
  311.  
  312.     mxres = scan_xres = axdpi[0] * 8;
  313.     myres = scan_yres = aydpi[0] * 14;
  314. /*    scan_bytes = ((((long)mxres) * ((long)myres)) / 8L);*/
  315.     scan_bytes = (long)(((((long)mxres + 15L)/16L)*2L)*(long)(myres));
  316.     prev_bytes = scan_bytes * 4L;
  317.     pbuff  = get_lcmem(200L);
  318.     scanptr = scanesc = (unsigned long)Malloc(scan_bytes);
  319.     if((!scanesc) || (!pbuff))
  320.     {
  321.          alert_cntre(ALERT14);
  322.          return(0);
  323.     }
  324.  
  325.  
  326.     if(!page_open())                    /* Open preview  */
  327.     {
  328.          alert_cntre(ALERT11);
  329.              close_vwork();
  330.          return(0);                /* exit if error */
  331.     }
  332.  
  333.  
  334.     page_MFDB.fd_stand = 0;                /* set up MFDB   */
  335.     page_MFDB.fd_nplanes = 1;                /* Mono only...  */
  336.     laser_MFDB.fd_stand = 0;
  337.     laser_MFDB.fd_nplanes = 1;
  338.  
  339.     for(i=0;i<16;i++) oldpal[i] = Setcolor(i,-1);       /* Save Colors   */
  340.  
  341.     set_icon_pos();
  342.     open_resource();                    /* open resources*/
  343.     open_windows();                    /* and windows...*/
  344. /*  graf_mouse(ARROW,0L);                * set to arrow..*/
  345.     return(1);                        /* and TTFN...   */
  346. }                            /* Ta Ta For Now */
  347.  
  348.  
  349.  
  350. /*************************************************************************/
  351. /* Function:    close_vwork()                             */
  352. /* Description: Close workstations, free memory, release resources.      */
  353. /*        This is used in case an error occurred allocating        */
  354. /*        buffers or opening workstations...             */
  355. /*************************************************************************/
  356. close_vwork()
  357. {
  358.    if(pbuff)
  359.        free(pbuff);
  360.    if(pagesc)
  361.            Mfree(pagesc);
  362.    if(scanesc)
  363.        Mfree(scanesc);
  364.    if(bltbuffer)
  365.           free(bltbuffer);
  366.    page_close();
  367.    gsx_mon();
  368.    rsrc_free();
  369.    v_clsvwk(rule_handle);
  370.    v_clsvwk(xor_handle);
  371.    v_clsvwk(shandle);
  372.    appl_exit();
  373.    exit(0);
  374. }
  375.  
  376.  
  377.  
  378. /*************************************************************************/
  379. /* Function:    close_work()                             */
  380. /* Description: Close workstations, free memory, release resources.      */
  381. /*        Used to exit the program...                   */
  382. /*************************************************************************/
  383. close_work()
  384. {
  385.     if(pbuff)
  386.        free(pbuff);
  387.     if(pagesc)
  388.            Mfree(pagesc);
  389.     if(scanesc)
  390.        Mfree(scanesc);
  391.     if(bltbuffer)
  392.            free(bltbuffer);
  393.     free_templates();
  394.     page_close();
  395.     IF_close();        /* GOG font manager */
  396.     shut_windows();
  397.     close_resource();
  398.     vex_butv(xor_handle,BADDR,&dummy);
  399.     Setpallete(oldpal);
  400.     gsx_mon();
  401.     v_clsvwk(rule_handle);
  402.     v_clsvwk(xor_handle);
  403.     v_clsvwk(shandle);
  404.     appl_exit();
  405.     exit(0);
  406. }
  407.  
  408.  
  409.  
  410. /*************************************************************************/
  411. /* Function:    laser_open()                         */
  412. /* Description: Open Laser Workstation                     */
  413. /*************************************************************************/
  414. laser_open(buffptr,x,y)
  415. long buffptr;
  416. int x;
  417. int y;
  418. {
  419.    register int i;
  420.    int pxy[4];
  421.    int mx,my;
  422.    int dpix;
  423.    int dpiy;
  424.  
  425.    intin[0] = 21;
  426.    for (i=1;i<10;i++) intin[i] = 1;
  427.    intin[10] = 2;
  428.    pageim = buffptr;
  429.    GDv_opnwk(intin,&phandle,intout,x,y,&pageim);
  430.    pxres = intout[0];
  431.    pyres = intout[1];
  432.    mx    = intout[3];            /* x and y microns of 1 pixel */
  433.    my    = intout[4];
  434.    if(phandle && pageim)        /* printer MUST return BUFFER!*/
  435.    {
  436.         pxy[0] = pxy[1] = 0;
  437.         laser_MFDB.fd_addr = pageim;
  438.         pxy[2] = laser_MFDB.fd_w = pxres; 
  439.         pxy[3] = laser_MFDB.fd_h = pyres;
  440.     laser_MFDB.fd_wdwidth = (pxres + 15)/16;
  441.         vs_clip(phandle,1,pxy);
  442.         if((mx != 85) && (my != 85))    /* if a laser...then 300dpi always */
  443.         {                /* cause 25400 would be 298dpi     */
  444.       dpix = 25400/mx;            /* 25400 microns per inch */
  445.           dpiy = 25400/my;        
  446.       axdpi[3] = xdpi[3] = dpix;    /* G.O. Graphics array... */
  447.           aydpi[3] = ydpi[3] = dpiy;    /* and CG array...        */
  448.  
  449.       half_xdpi[3] = dpix/2;    /* half of dpi...      */
  450.           half_ydpi[3] = dpiy/2;
  451.         }
  452. /*    laser_bytes = ((((long)pxres) * ((long)pyres))/8L);*/
  453.         laser_bytes = (long)(((((long)pxres + 15L)/16L)*2L)*(long)pyres);
  454.     IF_close();
  455.     IF_open(0);
  456.    }
  457.    return((phandle && pageim));   
  458. }
  459.  
  460.  
  461.  
  462. /*************************************************************************/
  463. /* Function:   laser_close()                         */
  464. /* Description: Close Laser Workstation                     */
  465. /*************************************************************************/
  466. laser_close()
  467. {
  468.    if(phandle)
  469.    {
  470.       vst_unload_fonts(phandle,0);
  471.       v_clswk(phandle);        
  472.    }                
  473. }
  474.  
  475.  
  476.  
  477. /*************************************************************************/
  478. /* Function:    page_open()                         */
  479. /* Description: Open memory driver Workstation                 */
  480. /*        Preview Buffer Workstation                 */
  481. /*************************************************************************/
  482. page_open()
  483. {
  484.     register int i;
  485.  
  486.     long tmpptr;
  487.  
  488.     intin[0] = 61;
  489.     for(i=1;i<10;i++) intin[i] = 1;
  490.     intin[10] = 2;
  491.     tmpptr = lmalloc(100L);
  492.     if(tmpptr)
  493.     {
  494.        GDv_opnwk(intin,&mhandle,intout,16,16,&tmpptr);
  495.        if(mhandle)
  496.            init_text(mhandle);
  497.        page_ptr = pagesc = (unsigned long)Malloc(prev_bytes); /*4xlegal size*/
  498.        if(mhandle && page_ptr)
  499.        {
  500.            GDvq_extnd(mhandle,0,intout,mxres,myres,&page_ptr);
  501.        pagebytes = prev_bytes;
  502.        }
  503.        free(tmpptr);
  504.     }
  505.     return((mhandle && page_ptr && tmpptr));
  506.  
  507. }
  508.  
  509.  
  510.  
  511. /*************************************************************************/
  512. /* Function:    page_close()                         */
  513. /* Description: Close memory driver workstation                 */
  514. /*        Preview Buffer Workstation                 */
  515. /*************************************************************************/
  516. page_close()
  517. {
  518.     if(mhandle)
  519.     {
  520.      vst_unload_fonts(mhandle,0);
  521.          v_clswk(mhandle);
  522.     }
  523. }
  524.  
  525.  
  526.  
  527. unsigned char *get_lmem(size)
  528. long size;
  529. {
  530.       unsigned char *memp;
  531.  
  532.       memp = lmalloc((long)size);
  533.       return(memp);
  534. }
  535.  
  536.  
  537. unsigned char *get_lcmem(size)
  538. long size;
  539. {
  540.      unsigned char *memp;
  541.   
  542.      memp = lcalloc(1L,size);
  543.      return(memp);
  544. }
  545.  
  546.  
  547.  
  548. adjustdpi()
  549. {
  550.    if(sdevm == 1)    /* medium rez */
  551.    {            /* vertical rez is 1/2 of hi res */
  552.       aydpi[0] = aydpi[1] = aydpi[2] = 40;
  553.       half_ydpi[0] = half_ydpi[1] = half_ydpi[2] = 20;
  554.       return;
  555.    }
  556.  
  557. /*   if((sxres > 640) && (syres > 400))    * large monitor */
  558.               /* it's not low, med or high! */
  559.    if( (sdevm > 2) || ((sdevm == 2) && ((sxres > 641) && (syres > 401))))
  560.    {                    /* 95 dpi        */
  561.       axdpi[0] = axdpi[1] = axdpi[2] = 95;
  562.       aydpi[0] = aydpi[1] = aydpi[2] = 95;
  563.       half_xdpi[0] = half_xdpi[1] = half_xdpi[2] = 47;
  564.       half_ydpi[0] = half_ydpi[1] = half_ydpi[2] = 47;
  565.  
  566.       sdevm = 0;
  567.       xdpi[0] = 95;        /* change GO Graphics dpi */
  568.       ydpi[0] = 95;        /* info for x and y dpi   */
  569.    }
  570. }
  571.